package com.itheima.web.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Banner;
import com.itheima.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;

    @GetMapping("/findByPage")
    public PageInfo<Banner> findByPage(@RequestParam(value = "pageNum",defaultValue = "1")Integer pageNum,
                                   @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize,String title){
        PageInfo<Banner> pageInfo = bannerService.findByPage(pageNum, pageSize,title);
        return pageInfo;
    }

    @PostMapping("/save")
    public String save(@RequestBody Banner banner){
        bannerService.save(banner);
        return "ok";
    }

    @GetMapping("/findById")
    public Banner findById(Integer id){
      return   bannerService.findById(id);
    }

    @DeleteMapping("/deleteById")
    public String deleteById(Integer id){
       bannerService.deleteById(id);
        return "ok";
    }

    @DeleteMapping("/deleteBatch")
    public String deleteBatch(Integer[] ids){
        bannerService.deleteBatch(ids);
        return "ok";
    }
}
